﻿using System.IO;
using System.Xml;
using Deferred.Library.Scene;
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Intermediate;

namespace Deferred.Editor
{
    public class SceneSerializer
    {
        public static SceneGraph readSceneGraph(string filename)
        {
            if (!File.Exists(filename))
            {
                writeSceneGraph(filename, new SceneGraph());
            }
            using (XmlReader reader = XmlReader.Create(filename))
            {
                return IntermediateSerializer.Deserialize<SceneGraph>(reader, filename);
            }

        }

        public static void writeSceneGraph(string filename, SceneGraph scene)
        {
            using (XmlWriter writer = XmlWriter.Create(filename))
            {
                IntermediateSerializer.Serialize<SceneGraph>(writer, scene, filename);
            }
        }
    }
}
